﻿using RpcHelper;
using SqlExecHelper;
using SqlExecHelper.SetColumn;

using Wedonek.RpcStore.Service.Model;

namespace Wedonek.RpcStore.Service.DAL
{
        internal class ErrorLangMsgDAL : SqlExecHelper.SqlBasicClass
        {
                public ErrorLangMsgDAL () : base ("ErrorLangMsg")
                {

                }
                public long GetErrorLangId (long errorId, string lang)
                {
                        return this.ExecuteScalar<long> ("Id", new ISqlWhere[] {
                                new SqlWhere("ErrorId", System.Data.SqlDbType.BigInt){Value=errorId},
                                new SqlWhere("Lang", System.Data.SqlDbType.VarChar,20){Value=lang}
                        });
                }
                public ErrorLang[] GetErrorMsg (long[] errorId)
                {
                        return this.Get<long, ErrorLang> ("ErrorId", errorId);
                }
                public ErrorLang[] GetErrorMsg (long[] errorId, string lang)
                {
                        return this.Get<long, ErrorLang> ("ErrorId", errorId, new ISqlWhere[]
                        {
                                new SqlWhere("Lang", System.Data.SqlDbType.VarChar,20){Value=lang}
                        });
                }
                public ErrorLang[] GetErrorMsg (long errorId)
                {
                        return this.Get<long, ErrorLang> ("ErrorId", errorId);
                }
                public void DropError (long errorId)
                {
                        if (!this.Drop ("ErrorId", errorId))
                        {
                                throw new ErrorException ("rpc.error.lang.drop.error");
                        }
                }
                public void SetErrorMsg (long id, string msg)
                {
                        if (!this.Update (new ISqlSetColumn[] {
                                new SqlSetColumn("Msg",  System.Data.SqlDbType.NVarChar,100){Value=msg}
                        }, "Id", id))
                        {
                                throw new ErrorException ("rpc.error.lang.set.error");
                        }
                }
                public void AddErrorMsg (ErrorLangAddParam add)
                {
                        this.Insert (add);
                }
                public void AddErrorMsg (ErrorLangAddParam[] adds)
                {
                        this.Insert (adds);
                }

                internal string GetErrorMsg (long errorId, string lang)
                {
                        return this.ExecuteScalar<string> ("Msg", new ISqlWhere[] {
                                new SqlWhere("ErrorId",  System.Data.SqlDbType.BigInt){Value=errorId},
                                new SqlWhere("Lang",  System.Data.SqlDbType.VarChar,20){Value=lang}
                        });
                }
        }
}
